const co = require('co')
const fs = require('fs')

const wjx = require('./wjx')
const conf = require('./conf')

let result = require('./result.json')

// B计划
co(function*() {
    let urls = conf.urls
    for (let i in urls) {
        let ret = yield wjx.query(urls[i])
        for (let j in ret) {
            console.log(`第${ret[j].topic}题`)
            result[ret[j].topic] = { '问': ret[j].question, '答': ret[j].answer }
        }
    }
    fs.writeFileSync('result.json', JSON.stringify(result, null, 2))
}).catch(function(err) {
    console.log(err)
})

/*
co(function*() {
    let page = yield wjx.getQuestion(conf.qid)
    console.log(page)
    setTimeout(function() {
        co(function*() {
            let answer = yield wjx.postAnswers(page)
            console.log(answer)
        }).catch(function(err) {
            console.log(err)
        })
    }, 1000 * 15) //  延时提交
}).catch(function(err) {
    console.log(err)
})
*/